package com.itcast.donkey.adapters;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.itcast.donkey.R;
import com.itcast.donkey.modles.NotesModles;
import com.squareup.picasso.Picasso;

import java.util.ArrayList;

/**
 * Created by lanouhn on 16/8/26.
 */
public class TravelNotesAdapter extends RecyclerView.Adapter<TravelNotesAdapter.NotesViewHolder> {

    private Context context;
    private ArrayList<NotesModles> notesModlesArrayList;

    public TravelNotesAdapter(Context context, ArrayList<NotesModles> notesModlesArrayList) {
        this.context = context;
        this.notesModlesArrayList = notesModlesArrayList;
    }

    @Override
    public NotesViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_travel_notes, null);
        NotesViewHolder holder = new NotesViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(NotesViewHolder holder, int position) {
        Picasso.with(context).load(notesModlesArrayList.get(position).getFront_cover_photo_url()).into(holder.ivItemNotesBg);
        Picasso.with(context).load(notesModlesArrayList.get(position).getUser().getImage()).into(holder.ivNotesIcon);
        holder.tvItemNotes.setText(notesModlesArrayList.get(position).getName());
        holder.tvNotesPhotosCount.setText(notesModlesArrayList.get(position).getPhotos_count() + "图");
        holder.tvNotesDays.setText(notesModlesArrayList.get(position).getDays() + "天");
        holder.tvNotesStart.setText(notesModlesArrayList.get(position).getStart_date());


    }

    @Override
    public int getItemCount() {
        return notesModlesArrayList.size();
    }

    public class NotesViewHolder extends RecyclerView.ViewHolder {
        private ImageView ivItemNotesBg;
        private TextView tvItemNotes;
        private TextView tvNotesStart;
        private TextView tvNotesDays;
        private TextView tvNotesPhotosCount;
        private ImageView ivNotesIcon;

        public NotesViewHolder(View itemView) {
            super(itemView);

            ivItemNotesBg = (ImageView) itemView.findViewById(R.id.iv_item_notes_bg);
            tvItemNotes = (TextView) itemView.findViewById(R.id.tv_item_notes_title);
            tvNotesStart = (TextView) itemView.findViewById(R.id.tv_notes_start);
            tvNotesDays = (TextView) itemView.findViewById(R.id.tv_notes_days);
            tvNotesPhotosCount = (TextView) itemView.findViewById(R.id.tv_notes_photos_count);
            ivNotesIcon = (ImageView) itemView.findViewById(R.id.iv_notes_icon);
        }
    }
}
